﻿/**
 * A FriendFeed Profile
 * 
 * @author	Lucas Araujo <araujo.lucas [at] gmail.com> - http://FriendFeed.com/LucasAraujo
 */
package friendfeed.api.data
{
	import flash.net.URLVariables;

	import friendfeed.api.FriendFeed;
	
	/**
	 * Profile
	 * This class is also used as "user" on Entry, Entry comments and Entry likes
	 */
	public class Profile
	{
		// status - Read-only
		// private or public 
		protected var _status:String;

		// id - Read-only
		// the user's FriendFeed UUID 
		protected var _id:String;

		// name
		// the user's full name 
		public var name:String;

		// nickname - Read-only
		// the user's FriendFeed nickname, used in FriendFeed URLs 
		protected var _nickname:String;

		// profileUrl - Read-only
		// the user's profile URL on FriendFeed 
		protected var _profileUrl:String;

		// services - Read-only
		// the services connected to the user's account
		protected var _services:Array;

		// subscriptions - Read-only
		// the users this user is subscribed to
		protected var _subscriptions:Array;

		// rooms - Read-only
		// the rooms this user is a member of
		protected var _rooms:Array;

		// lists - Read-only
		// the lists this user is a member of (only visible if authenticated as this user)
		protected var _lists:Array;

		// For update profile only:
			
		// Picture
		public var picture:*;

		/**
		 * Profile
		 * If you want to update your profile, set name and picture properties
		 * 
		 * Usage:
		 * <code>
		 *    var profile:Profile = new Profile("your new name");
		 *    var friendFeed:FriendFeed = new FriendFeed("nickname", "remotekey");
		 *    friendFeed.addEventListener(FriendFeedEvent.ON_SET_PROFILE_RESULT, resultHandler);
		 *    friendFeed.setProfile("nickname", profile);
		 * </code>
		 * 
		 * @param	name
		 * @param	picture
		 */
		public function Profile(name:String=null, picture:*=null):void
		{
			this.name = name;
			this.picture = picture;
		}
		 
		/**
		 * 
		 * @param	obj
		 * @return	Profile
		 */
		public static function newFromJSON(obj:Object):Profile
		{
			var profile:Profile = new Profile();
			profile._status = obj.status;
			profile._id = obj.id;
			profile.name = obj.name;
			profile._nickname = obj.nickname;
			profile._profileUrl = obj.profileUrl;
			profile._services = obj.services;
			profile._subscriptions = obj.subscriptions;
			profile._rooms = obj.rooms;
			profile._lists = obj.lists;
			return profile;
		}

		/**
		 * 
		 * @return	URLVariable	for post
		 */
		public function getURLVariables():URLVariables
		{
			var variables:URLVariables = new URLVariables();
			if (this.name != null)
				variables.name = this.name;
			if (this.picture != null)
				variables.picture = this.picture;
			return variables;
		}

		/**
		 * Get User's Profile Picture URL
		 * 
		 * @param	size
		 * @return	An url
		 */
		public function getPictureUrl(size:String=null):String
		{
			var ff:FriendFeed = new FriendFeed();
			return ff.getUserPictureURL(this.nickname, size);
		}
		
		/**
		 * toString
		 * 
		 * @return
		 */
		public function toString():String
		{
			return "(Profile id: "+ this.id +" nickname: "+ this.nickname +")";
		}
		
		// Setters and getters
		
		public function get status():String { return this._status; }
		public function get id():String { return this._id; }
		public function get nickname():String { return this._nickname; }
		public function get profileUrl():String { return this._profileUrl; }
		public function get services():Array { return this._services; }
		public function get subscriptions():Array { return this._subscriptions; }
		public function get rooms():Array { return this._rooms; }
		public function get lists():Array { return this._lists; }
	}
	
}